LF_BET_TYPE = {
    '110': {'name': "首位数投"},
    '120': {'name': "首位红投"},
    '201': {'name': "二连直"},
    '202': {'name': "二连组"},
    '331': {'name': "前三直"},
    '332': {'name': "前三组"},
    '207': {'name': "幸运二"},
    '307': {'name': "幸运三"},
    '407': {'name': "幸运四"},
    '507': {'name': "幸运五"}
}

PK10_BET_TYPE = {
    '1': {'name': "猜冠军"},
    '2': {'name': "猜前二"},
    '3': {'name': "猜前三"},
    '4': {'name': "猜前四"},
    '5': {'name': "猜前五"},
    '6': {'name': "定位胆"},
    '7': {'name': "冠军大小单双"},
    '8': {'name': "亚军大小单双"},
    '9': {'name': "季军大小单双"},
    '10': {'name': "龙虎"}
}


SSC_BET_TYPE = {
    '100': {'name': "定位胆"},
    '230': {'name': "后二直选复式"},
    '231': {'name': "后二直选单式"},
    '232': {'name': "后二组选复式"},
    '235': {'name': "后二直选和值"},
    '310': {'name': '前三直选复式'},
    '311': {'name': '前三直选单式'},
    '313': {'name': '前三组三'},
    '316': {'name': '前三组六'},
    '320': {'name': "中三直选复式"},
    '321': {'name': "中三直选单式"},
    '323': {'name': "中三组三"},
    '326': {'name': "中三组六"},
    '330': {'name': "后三直选复式"},
    '331': {'name': "后三直选单式"},
    '333': {'name': "后三组三"},
    '336': {'name': "后三组六"},
    '410': {'name': "前四直选"},
    '430': {'name': "后四直选"},
    '500': {'name': "五星直选"},
    '501': {'name': "五星通选"},
    '200': {'name': "大小单双"},
    '209': {'name': "好事成双"},
    '309': {'name': "三星报喜"},
    '409': {'name': "四季发财"},
    '102': {'name': "庄闲"},
    '104': {'name': "对子"},
    '106': {'name': "豹子"},
    '108': {'name': "天王"},
    '240': {'name': "总和大小单双"},
    '242': {'name': "前二大小单双"},
    '244': {'name': "后二大小单双"},
    '246': {'name': "龙虎"},
}

KS_BET_TYPE = {
    '1': {'name': "和值"},
    '2': {'name': "三同号单选"},
    '3': {'name': "三同号通选"},
    '4': {'name': "二同号单选"},
    '5': {'name': "二同号复选"},
    '6': {'name': "三不同号"},
    '7': {'name': "二不同号"},
    '8': {'name': "三连号通选"},
    '9': {'name': "任一"}
}

CP11X5_BET_TYPE = {
    '1': {'name': "任选二"},
    '2': {'name': "任选三"},
    '3': {'name': "任选四"},
    '4': {'name': "任选五"},
    '5': {'name': "任选六"},
    '6': {'name': "任选七"},
    '7': {'name': "任选八"},
    '8': {'name': "前一"},
    '9': {'name': "前二直选"},
    '10': {'name': "前二组选"},
    '11': {'name': "前三直选"},
    '12': {'name': "前三组选"},
    '13': {'name': "任选一"},
    '14': {'name': "龙虎"},
    '15': {'name': "庄闲"},
}

TC_PLS_BET_TYPE = {
    '301': {'name': "三星直选"},
    '302': {'name': "三星直选和值"},
    '303': {'name': "三星组三"},
    '304': {'name': "三星组六"},
    '305': {'name': "三星组选和值"},
    '306': {'name': "不定位"},
    '307': {'name': "定位胆"},
    '201': {'name': "二星直选"},
    '202': {'name': "二星直选和值"},
    '203': {'name': "二星组选"},
    '204': {'name': "二星组选和值"},
    '205': {'name': "大小单双"}
}

PLATE_BET_TYPE = {
    '102': {'name': "庄闲"},
    '104': {'name': "对子"},
    '106': {'name': "豹子"},
    '108': {'name': "天王"}
}

BACCARAT_BET_TYPE = {
    '240': {'name': "总和大小单双"},
    '242': {'name': "前二大小单双"},
    '244': {'name': "后二大小单双"},
    '246': {'name': "龙虎斗"}
}

LOTTERY_KEY_MAPPER = {
    '1': {'name': "重庆时时彩",
          'third_type': SSC_BET_TYPE},
    '3': {'name': "江苏快三",
          'third_type': KS_BET_TYPE},
    '4': {'name': "山东11选5",
          'third_type': CP11X5_BET_TYPE},
    '6': {'name': "天津时时彩",
          'third_type': SSC_BET_TYPE},
    '7': {'name': "新疆时时彩",
          'third_type': SSC_BET_TYPE},
    '8': {'name': "江西11选5",
          'third_type': CP11X5_BET_TYPE},
    '9': {'name': "广东11选5",
          'third_type': CP11X5_BET_TYPE},
    '10': {'name': "上海11选5",
           'third_type': CP11X5_BET_TYPE},
    '11': {'name': "广西快3",
           'third_type': KS_BET_TYPE},
    '12': {'name': "北京PK10",
           'third_type': PK10_BET_TYPE},
    '13': {'name': "重庆幸运农场",
           'third_type': TC_PLS_BET_TYPE},
    '15': {'name': "福彩3D",
           'third_type': TC_PLS_BET_TYPE},
    '17': {'name': "幸运分分彩",
           'third_type': SSC_BET_TYPE},
    '18': {'name': "极速11选5",
           'third_type': CP11X5_BET_TYPE},
    '19': {'name': "极速快3",
           'third_type': KS_BET_TYPE},
    '20': {'name': "极速PK10",
           'third_type': PK10_BET_TYPE},
    '21': {'name': '幸运百家乐',
           'third_type': BACCARAT_BET_TYPE},
    '22': {'name': '幸运两面盘',
           'third_type': PLATE_BET_TYPE}
}


EVENT_RULES = {
    "aggs": {
        "groups": [
            {
                "group_name": "彩种/玩法",
                "field_id": "cp_lottery_sub_type",
                "is_keyword": False,
                "field_name": "彩种",
                "sub_fields": [
                    {
                        "field_id": "cp_lottery_third_type",
                        "is_keyword": False,
                        "field_name": "玩法"
                    },
                ]
            },
            {
                "group_name": "渠道",
                "field_id": "_chn",
                "is_keyword": True,
                "field_name": "渠道"
            }

        ],
        "values": [
            {
                "value_id": "cp_lottery_price",
                "value_name": "投注",
                "fmt": "\"%.2f\" % a",
                "adjust_amount": True,
            },
            {
                "value_id": "cp_lottery_win",
                "value_name": "中奖",
                "fmt": "\"%.2f\" % a",
                "adjust_amount": True,
            },
            {
                "value_id": "cp_lottery_bonus",
                "value_name": "派奖",
                "fmt": "\"%.2f\" % a",
                "adjust_amount": True,
            },
            {
                "value_id": "cp_lottery_refund",
                "value_name": "退款金额",
                "fmt": "\"%.2f\" % a",
                "adjust_amount": True,
            },
            {
                "value_id": "cp_lottery_profit",
                "value_name": "利润",
                "value_expr": "cp_lottery_price - cp_lottery_refund - cp_lottery_win - cp_lottery_bonus",
                "fmt": "\"%.2f\" % v",
                "adjust_amount": True,
            },
            {
                "value_id": "cp_lottery_profit_rate",
                "value_name": "利润率",
                "value_expr": ("(cp_lottery_price - cp_lottery_refund - cp_lottery_win - cp_lottery_bonus)/"
                               "(cp_lottery_price - cp_lottery_refund)"),
                "fmt": "\"%.2f\" % (v * 100)"
            }
        ],
        "uv": {
            "field_id": "_user_id",
            "field_name": "投注人次"
        },
        "pv": {
            "field_name": "投注次数"
        }
    }
}


EVENT_CONFIG = {
    "event_id": "cp_lottery",
    "event_name": "购彩分析",
    "values": {
        "_user_id": {
            "field_name": "用戶ID",
            "value_type": "long"
        },
        "seq_no": {
            "field_name": "期号",
            "value_type": "string",
            "required": False
        },
        "sub_type": {
            "field_name": "彩種",
            "value_type": "long",
            "enum": {
                "target_enum_dct": LOTTERY_KEY_MAPPER
            }
        },
        "third_type": {
            "field_name": "玩法",
            "value_type": "long",
            "enum": {
                "inherent": "sub_type"
            }
        },
        "out_trans_id": {
            "field_name": "訂單ID",
            "value_type": "long"
        },
        "bet_target": {
            "field_name": "投注对象",
            "value_type": "string",
            "required": False
        },
        "price": {
            "field_name": "投注",
            "value_type": "float",
        },
        "win": {
            "field_name": "中奖",
            "value_type": "float",
        },
        "bonus": {
            "field_name": "加獎",
            "value_type": "float",
        },
        "refund": {
            "field_name": "退款金额",
            "value_type": "float"
        },
        "profit": {
            "field_name": "盈利",
            "value_type": "float",
            "required": False
        }
    },
    "rule": EVENT_RULES
}




